﻿using System;
using GameOn.Web.Entities;

namespace GameOn.Web.Services
{
    /// <summary>
    /// A Ranking history logging service
    /// </summary>
    public class RankHistoryLoggingService: IRankHistoryLoggingService
    {
        private GameOnEntities Entities { get; set; }

        public RankHistoryLoggingService(GameOnEntities entities)
        {
            Entities = entities;
        }

        /// <summary>
        /// Saves a ranking history record for a player
        /// </summary>
        public void SaveRankHistory(Player player)
        {
            var rankHistory = new RankHistory { Player = player, Rank = player.CurrentRank, RankDate = DateTime.Now };
            Entities.CreateObjectSet<RankHistory>().AddObject(rankHistory);
            Entities.SaveChanges();
        }
    }
}
